<?php
	include "layout.php";
	
	head("Edit Planet");
?>
<h1>Edit a Planet</h1>
<?php 
	if (!isset($_GET["id"])) {
		header("Location: planets.php");
	}
	$id = $_GET["id"];
	$planetq = mysql_query("SELECT * FROM planets where id={$id}");
	$planet = mysql_fetch_array($planetq);
	$name = $planet["name"];
	$size = $planet["size"];
	if (isset($_POST["submit"])) {
		edit_planet();
	}
	echo <<<Form
<form name="editplanet" action="editplanet.php?id={$id}" method="post">
	<label for="name">Planet Name:</label>
	<input type="text" name="name" placeholder="Planet Name" value="{$name}" /><br />
	<label for="size">Planet Size:</label>
	<select name="size">
		<option value=0>--</option>
Form;
	for ($i = 1; $i <= 30; $i++) {
		if ($i == $size){
			echo "<option value={$i} selected>{$i}</option>";
		}
		else {
			echo "<option value={$i}>{$i}</option>";
		}
	}
	echo <<<Form
	</select><br />
	<input type="submit" name="submit" value="Edit" /> 
</form>
Form;
?>
<?php 
	foot();
?>